package cn.tedu.micro.demo.device.service.impl;

import cn.tedu.micro.demo.common.pojo.po.GunInfoPO;
import cn.tedu.micro.demo.common.pojo.vo.GunInfoVO;
import cn.tedu.micro.demo.device.mapper.GunInfoMapper;
import cn.tedu.micro.demo.device.service.DeviceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private GunInfoMapper gunInfoMapper;
    //等待实现业务逻辑
    @Override
    public GunInfoVO getGunInfo(Integer gunId) {
        //每一步都封装一个对应的方法 方便阅读核心流程
        //1.利用gunId 查询gunInfoPO
        GunInfoPO po=getGunById(gunId);
        //2.将po转化成vo
        GunInfoVO vo=convertPo2Vo(po);
        return vo;
    }
    //如果po不空 返回vo 如果po是空 返回null
    private GunInfoVO convertPo2Vo(GunInfoPO po) {
        //1.有可能数据库持久层查询的po不存在
        GunInfoVO vo=null;
        if (po!=null){
            //数据库命中 才封装vo返回
            vo=new GunInfoVO(po.getId(),po.getStatus(),po.getType());
        }
        return vo;
    }

    private GunInfoPO getGunById(Integer gunId) {
        //select id,status,type,create_time,update_time where id=?
        return gunInfoMapper.selectById(gunId);
    }

}
